using System;
using System.Runtime.Serialization;

namespace Metro.Admin.BusinessEntities
{
    [DataContract]
	public class Company {

        private string id = string.Empty;
        private string name = string.Empty;

        private decimal average = 0;
        private decimal open = 0;
        private decimal close = 0;
        private decimal minimal = 0;
        private decimal maximum = 0;

        private decimal avgBuy=0;
        private decimal avgSell=0;
       
        private decimal maximalAmount = 0;
        private decimal maximalPrice = 0;
        private decimal minimalAmount = 0;
        private decimal minimalPrice = 0;
        private decimal taxBase = 0;
        private decimal taxPercentage = 0;
        private DateTime closeNextDay;
        private DateTime closeSpot;
        private DateTime openNextDay;
        private DateTime openSpot;
        private Market currentMarket = Market.Spot;
        private int transactionDeleteExpiration = 60;
        private bool platformSuspend = false;

		public Company(){}



        [DataMember]
        public String Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        [DataMember]
        public String Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        [DataMember]
        public Decimal Average
        { 
            get { return this.average; }
            set { this.average = value; }
        }

        [DataMember]
        public Decimal Open
        {
            get { return this.open; }
            set { this.open = value; }
        }

        [DataMember]
        public Decimal Close
        {
            get { return this.close; }
            set { this.close = value; }
        }

        [DataMember]
        public Decimal Minimal
        {
            get { return this.minimal; }
            set { this.minimal = value; }
        }

        [DataMember]
        public Decimal Maximum
        {
            get { return this.maximum; }
            set { this.maximum = value; }
        }

        [DataMember]
        public Decimal AvgBuy
        {
            get { return this.avgBuy; }
            set { this.avgBuy = value; }
        }

        [DataMember]
        public Decimal AvgSell
        {
            get { return this.avgSell; }
            set { this.avgSell = value; }
        }

        [DataMember]
        public Decimal TaxBase
        {
            get { return this.taxBase; }
            set { this.taxBase = value; }
        }

        [DataMember]
        public Decimal TaxPercentage
        {
            get { return this.taxPercentage; }
            set { this.taxPercentage = value; }
        }

        [DataMember]
        public DateTime CloseNextDay
        {
            get { return this.closeNextDay; }
            set { this.closeNextDay = value; }
        }

        [DataMember]
        public DateTime CloseSpot
        {
            get { return this.closeSpot; }
            set { this.closeSpot = value; }
        }

        [DataMember]
        public DateTime OpenNextDay
        {
            get { return this.openNextDay; }
            set { this.openNextDay = value; }
        }

        [DataMember]
        public DateTime OpenSpot
        {
            get { return this.openSpot; }
            set { this.openSpot = value; }
        }

        [DataMember]
        public Decimal MaximalPrice
        {
            get { return this.maximalPrice; }
            set { this.maximalPrice = value; }
        }

        [DataMember]
        public Decimal MinimalPrice
        {
            get { return this.minimalPrice; }
            set { this.minimalPrice = value; }
        }

        [DataMember]
        public Decimal MaximalAmount
        {
            get { return this.maximalAmount; }
            set { this.maximalAmount = value; }
        }

        [DataMember]
        public Decimal MinimalAmount
        {
            get { return this.minimalAmount; }
            set { this.minimalAmount = value; }
        }

        [DataMember]
        public int TransactionDeleteExpiration
        {
            get { return this.transactionDeleteExpiration; }
            set { this.transactionDeleteExpiration = value; }
        }

        [DataMember]
        public bool PlatformSuspend
        {
            get { return this.platformSuspend; }
            set { this.platformSuspend = value; }
        }
        
        public DateTime GetCloseCurrentMarket()
        {
            DateTime close = DateTime.Now;

            if (this.currentMarket.Equals(Market.Spot))
            {
                close = this.closeSpot;     
            }
            if (this.currentMarket.Equals(Market.NextDay))
            { 
                close = this.closeNextDay;  
            }

            return close;
        }

        public Market GetCurrentMarket()
        {
            DateTime currentTime = DateTime.Now;

            if (currentTime >= this.openSpot && currentTime <= this.closeSpot)
                currentMarket = Market.Spot;
            else if (currentTime >= this.openNextDay && currentTime <= this.closeNextDay)
                currentMarket = Market.NextDay;
            else
                currentMarket = Market.NoMarket;

            return this.currentMarket;  
        }

    
    }
}